package com.agileboot.attendance.domain.personnel.model;

import com.agileboot.attendance.domain.personnel.db.AttPersonnelEntity;
import com.agileboot.attendance.domain.personnel.db.AttPersonnelService;
import com.agileboot.attendance.domain.supplier.db.AttSupplierService;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 人员模型工厂类
 * </p>
 *
 * @author agileboot
 * @since 2023-03-14
 */
@Component
@RequiredArgsConstructor
public class PersonnelModelFactory {

    private final AttPersonnelService personnelService;
    private final AttSupplierService supplierService;

    /**
     * 创建空的人员模型
     *
     * @return 人员模型
     */
    public PersonnelModel create() {
        return new PersonnelModel(personnelService, supplierService);
    }

    /**
     * 根据ID加载人员模型
     *
     * @param personnelId 人员ID
     * @return 人员模型
     */
    public PersonnelModel loadById(Long personnelId) {
        AttPersonnelEntity entity = personnelService.getById(personnelId);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.PERSONNEL_NOT_FOUND);
        }
        return new PersonnelModel(entity, personnelService, supplierService);
    }
} 